package id.co.rho.scoring.cid.changecontrol.entitychange.propertychange;

import id.co.rho.scoring.cid.changecontrol.entitychange.UpdateEntityChange;

import java.io.Serializable;


public class PropertyChange extends UpdateEntityChange {
	private String propertyName;
	private Serializable oldValue;
	private Serializable newValue;

    public PropertyChange() {
    }

    public PropertyChange(String propertyName, Serializable oldValue, Serializable newValue) {
		super();
		this.propertyName = propertyName;
		this.oldValue = oldValue;
		this.newValue = newValue;
	}

	public String getPropertyName() {
		return propertyName;
	}

	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	public Serializable getOldValue() {
		return oldValue;
	}

	public void setOldValue(Serializable oldValue) {
		this.oldValue = oldValue;
	}

	public Serializable getNewValue() {
		return newValue;
	}

	public void setNewValue(Serializable newValue) {
		this.newValue = newValue;
	}

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        PropertyChange that = (PropertyChange) o;

        if (newValue != null ? !newValue.equals(that.newValue) : that.newValue != null) return false;
        if (oldValue != null ? !oldValue.equals(that.oldValue) : that.oldValue != null) return false;
        if (propertyName != null ? !propertyName.equals(that.propertyName) : that.propertyName != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (propertyName != null ? propertyName.hashCode() : 0);
        result = 31 * result + (oldValue != null ? oldValue.hashCode() : 0);
        result = 31 * result + (newValue != null ? newValue.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "PropertyChange{" +
                "propertyName='" + propertyName + '\'' +
                ", oldValue=" + oldValue +
                ", newValue=" + newValue +
                '}';
    }
}
